package com.example.MA.common.lang;

import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

/**
 * @author Corn
 *
 */
@Data
@NoArgsConstructor
public class Result implements Serializable {
    private int code;
    private String msg;
    private Object data;

    /**
     *
     * @param data 传输数据
     * @return 返回Result
     *
     */
    public static Result success(Object data) {
        Result r = new Result();
        r.setCode(666);
        r.setMsg("成功");
        r.setData(data);
        return r;
    }


    public static Result success(String msg, Object data) {
        Result r = new Result();
        r.setCode(666);
        r.setMsg(msg);
        r.setData(data);
        return r;
    }

    /**
     *
     * @param code 错误代码
     * @param msg 错误消息
     * @param data 失败数据 一般为null
     * @return 返回Result
     */
    public static Result fail(int code, String msg, Object data) {
        Result r = new Result();
        r.setCode(code);
        r.setMsg(msg);
        r.setData(data);
        return r;
    }

}

